﻿package mortal.game.view.signUp.view
{
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.view.signUp.data.*;
    import mortal.game.view.signUp.util.*;
    import mortal.mvc.core.*;

    public class SignUpCategorySpr extends GSprite
    {
        private var _tagVec:Vector.<SignUpCategoryTag>;
        private var _tabObj:Object;
        private var _effectLayer:EffectLayer;
        private var _tagSpr:GSprite;
        private var _currSelTagIndex:int = -1;

        public function SignUpCategorySpr()
        {
            this._tagVec = new Vector.<SignUpCategoryTag>;
            this._tabObj = {};
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._tagSpr = UICompomentPool.getUICompoment(GSprite);
            this._tagSpr.mouseEnabled = true;
            this.addChild(this._tagSpr);
            this._tagSpr.configEventListener(MouseEvent.CLICK, this.onListClickHandler);
            this._effectLayer = UICompomentPool.getUICompoment(EffectLayer);
            this._effectLayer.x = 100 - 8;
            this._effectLayer.y = 40 - 2;
            this.addChild(this._effectLayer);
            this.checkTagIsSatisfy();
            this.configEventListener(MouseEvent.MOUSE_OVER, this.onOverHandler);
            this.configEventListener(MouseEvent.MOUSE_OUT, this.onOutHandler);
            return;
        }// end function

        private function onTabBarChangeHandler(event:Event = null) : void
        {
            return;
        }// end function

        private function initTag() : void
        {
            var _loc_1:SignUpCategoryTag = null;
            for each (_loc_1 in this._tagVec)
            {
                
                _loc_1.data = SignUpUtil.getCategoryData(_loc_1.tabIndex);
            }
            return;
        }// end function

        public function checkTagIsSatisfy() : void
        {
            var _loc_3:SignUpCategoryTag = null;
            var _loc_4:Array = null;
            this.clearTab();
            Cache.instance.signUp.SetTagNameDic();
            var _loc_1:int = 0;
            var _loc_2:int = 0;
            while (_loc_2 < SignUpConst.Tag_TotalNum)
            {
                
                if (Cache.instance.signUp.getTagOpenStateByIndex(_loc_2) == 0)
                {
                    _loc_3 = UICompomentPool.getUICompoment(SignUpCategoryTag);
                    _loc_4 = SignUpTabType.tabArr;
                    _loc_3.tabType = _loc_4[_loc_2];
                    _loc_3.tabIndex = int(SignUpTabType.tabIndexObj[_loc_3.tabType]);
                    _loc_3.x = 0;
                    _loc_3.y = 59 * _loc_1;
                    this._tabObj[SignUpTabType.tabArr[_loc_2]] = _loc_3;
                    this._tagSpr.addChild(_loc_3);
                    this._tagVec.push(_loc_3);
                    _loc_1++;
                }
                _loc_2++;
            }
            this.initTag();
            return;
        }// end function

        public function updateTabData() : void
        {
            var _loc_4:WelfareTabData = null;
            var _loc_5:Array = null;
            var _loc_6:SignUpCategoryData = null;
            Cache.instance.signUp.SetTagNameDic();
            var _loc_1:Array = [];
            var _loc_2:int = 0;
            while (_loc_2 < SignUpConst.Tag_TotalNum)
            {
                
                if (Cache.instance.signUp.getTagOpenStateByIndex(_loc_2) == 0)
                {
                    _loc_4 = new WelfareTabData();
                    _loc_5 = SignUpTabType.tabArr;
                    _loc_4.tabType = _loc_5[_loc_2];
                    _loc_4.tabIndex = int(SignUpTabType.tabIndexObj[_loc_4.tabType]);
                    _loc_6 = SignUpUtil.getCategoryData(_loc_4.tabIndex);
                    _loc_4.tabNameRes = _loc_6.resName;
                    _loc_1.push(_loc_4);
                }
                _loc_2++;
            }
            var _loc_3:* = new DataProvider();
            _loc_3.addItems(_loc_1);
            return;
        }// end function

        private function clearTab() : void
        {
            var _loc_1:SignUpCategoryTag = null;
            for each (_loc_1 in this._tagVec)
            {
                
                _loc_1.dispose();
            }
            this._tagVec = new Vector.<SignUpCategoryTag>;
            this._tabObj = {};
            return;
        }// end function

        private function setDefaultSelTag() : void
        {
            this.switchTag(this._tagVec[0]);
            Dispatcher.dispatchEvent(new DataEvent(EventName.SignUpSwitchTag, SignUpConst.Tag_DailySignUp));
            return;
        }// end function

        private function onListClickHandler(event:MouseEvent) : void
        {
            var _loc_2:* = event.target as SignUpCategoryTag;
            if (_loc_2)
            {
                this.switchTag(_loc_2);
                Dispatcher.dispatchEvent(new DataEvent(EventName.SignUpSwitchTag, _loc_2.tabIndex));
            }
            return;
        }// end function

        private function switchTag(param1:SignUpCategoryTag) : void
        {
            var _loc_2:SignUpCategoryTag = null;
            if (param1)
            {
                if (param1.tabIndex == this._currSelTagIndex)
                {
                    return;
                }
                for each (_loc_2 in this._tagVec)
                {
                    
                    if (_loc_2.tabIndex == param1.tabIndex)
                    {
                        _loc_2.isSel = true;
                        continue;
                    }
                    _loc_2.isSel = false;
                }
                this._currSelTagIndex = param1.tabIndex;
            }
            return;
        }// end function

        public function switchTagByIndex(param1:int) : void
        {
            var _loc_2:SignUpCategoryTag = null;
            for each (_loc_2 in this._tagVec)
            {
                
                if (_loc_2.tabIndex == param1)
                {
                    this.switchTag(_loc_2);
                    break;
                }
            }
            return;
        }// end function

        private function onPageChange(event:Event) : void
        {
            return;
        }// end function

        public function updateAllRewardTab() : void
        {
            var _loc_2:String = null;
            var _loc_1:* = Cache.instance.signUp.hasRewardFlagObject;
            for (_loc_2 in _loc_1)
            {
                
                this.updateSingleTabShine(_loc_2);
            }
            return;
        }// end function

        public function updateSingleTabShine(param1:String) : void
        {
            var _loc_2:* = Cache.instance.signUp.hasRewardFlagObject;
            var _loc_3:* = this._tabObj[param1];
            if (_loc_3)
            {
                if (_loc_2[param1])
                {
                    _loc_3.isShowArroundEffect = true;
                }
                else
                {
                    _loc_3.isShowArroundEffect = false;
                }
            }
            return;
        }// end function

        private function onOverHandler(event:MouseEvent) : void
        {
            CursorManager.showCursor(CursorManager.BUTTON);
            return;
        }// end function

        private function onOutHandler(event:MouseEvent) : void
        {
            CursorManager.hideFromButton();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this.clearTab();
            this._tagSpr.dispose(param1);
            this._effectLayer.dispose();
            this._tagSpr = null;
            this._effectLayer = null;
            this._tagVec.length = 0;
            this._currSelTagIndex = -1;
            return;
        }// end function

    }
}
